package com.maiji.cloud.service.impl;

import cn.jiguang.common.TimeUnit;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.google.common.collect.Maps;
import com.maiji.cloud.config.MyRedisConfig;
import com.maiji.cloud.entities.community.ComComment;
import com.maiji.cloud.entities.community.ComMiddleUserMessage;
import com.maiji.cloud.entities.community.ComMsgInfo;
import com.maiji.cloud.entities.community.ComUserMessage;
import com.maiji.cloud.entities.login.AppUser;
import com.maiji.cloud.entities.login.UploadRecord;
import com.maiji.cloud.entities.login.UserInfo;
import com.maiji.cloud.mapper.ComCommentMapper;
import com.maiji.cloud.mapper.ComMiddleUserMessageMapper;
import com.maiji.cloud.mapper.ComMsgInfoMapper;
import com.maiji.cloud.mapper.ComUserMessageMapper;
import com.maiji.cloud.microservice.UploadRecordService;
import com.maiji.cloud.microservice.UserInfoService;
import com.maiji.cloud.request.BaseInputDto;
import com.maiji.cloud.request.community.ComCommentMsgInputDto;
import com.maiji.cloud.request.community.ComUserMessageInputDto;
import com.maiji.cloud.request.community.ComUserMessageQueryInputDto;
import com.maiji.cloud.response.BaseOutPutDto;
import com.maiji.cloud.response.Status;
import com.maiji.cloud.response.community.*;
import com.maiji.cloud.response.login.UploadImageResData;
import com.maiji.cloud.response.login.UserInfoResData;
import com.maiji.cloud.service.ComUserMessageService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.maiji.cloud.service.CommunityService;
import com.maiji.cloud.utils.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;

import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2019-10-12
 */
@Service
@Transactional
public class ComUserMessageServiceImpl extends ServiceImpl<ComMiddleUserMessageMapper,ComMiddleUserMessage> implements ComUserMessageService {

    @Value("${apnsProduction}")
    private Boolean apnsProduction;

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Autowired
    ComMiddleUserMessageMapper comMiddleUserMessageMapper;

    @Autowired
    ComMsgInfoMapper comMsgInfoMapper;

    @Autowired
    ComCommentMapper comCommentMapper;

    @Autowired
    UploadRecordService uploadRecordService;

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    @Lazy
    CommunityService communityService;

    /**
     * 社区消息数量
     * @param inputDto
     * @param maijiToken
     * @return
     */
    public BaseOutPutDto<ComUserMsgCountOutPutDto> messageCount(@RequestBody BaseInputDto inputDto, @RequestHeader("maijiToken")String maijiToken){
        BaseOutPutDto<ComUserMsgCountOutPutDto> outPutDto = new BaseOutPutDto();
        ComUserMsgCountOutPutDto userMsgCountOutPutDto = new ComUserMsgCountOutPutDto();
        try {
            AppUser appUser = RedisUtil.getAppUserByRedis(redisTemplate, MyRedisConfig.REDISDATABASENO, maijiToken, userInfoService);
            if(appUser != null){
                String userId = appUser.getUuId();
                EntityWrapper<ComMiddleUserMessage> entityWrapper = new EntityWrapper<>();
                ComMiddleUserMessage middleUserMessage = new ComMiddleUserMessage();
                middleUserMessage.setTargetUserId(userId);
                middleUserMessage.setIsRead(0);
                entityWrapper.setEntity(middleUserMessage);
                List<ComMiddleUserMessage> userMessages = comMiddleUserMessageMapper.selectList(entityWrapper);

                Integer commentCount = 0;
                Integer atCount = 0;
                Integer praiseCount = 0;
                Integer followerCount = 0;
                Integer replyCount = 0;
                Integer comCommentCount = 0;

                for (ComMiddleUserMessage usermessage:userMessages) {
                    if(usermessage.getType() == ComUserMessageTypeEnum.Comment.getValue()){
                        commentCount += 1;
                    }else if(usermessage.getType() == ComUserMessageTypeEnum.Praise.getValue()){
                        praiseCount += 1;
                    }else if(usermessage.getType() == ComUserMessageTypeEnum.Follow.getValue()){
                        followerCount += 1;
                    }else if(usermessage.getType() == ComUserMessageTypeEnum.Reply.getValue()){
                        replyCount += 1;
                    }else if(usermessage.getType() == ComUserMessageTypeEnum.At.getValue()){
                        atCount += 1;
                    }else if(usermessage.getType() == ComUserMessageTypeEnum.CommentComment.getValue()){
                        comCommentCount += 1;
                    }
                }
                userMsgCountOutPutDto.setCommentCount(commentCount);
                userMsgCountOutPutDto.setComCommentCount(comCommentCount);
                userMsgCountOutPutDto.setAtCount(atCount);
                userMsgCountOutPutDto.setPraiseCount(praiseCount);
                userMsgCountOutPutDto.setFollowerCount(followerCount);
                userMsgCountOutPutDto.setReplyCount(replyCount);
                userMsgCountOutPutDto.setUserId(userId);

                outPutDto.setData(userMsgCountOutPutDto);
                outPutDto.setStatus(Status.SUCCESS);
            }else{
                outPutDto.setStatus(Status.TOKENINVALID);
            }

            return outPutDto;
        }catch (Exception exc){
            outPutDto.setStatus(Status.ERROR);
            outPutDto.setMessage(exc.getMessage());
            return outPutDto;
        }
    }

    /**
     * 创建一条社区消息
     * @param inputDto
     * @return
     */
    public BaseOutPutDto createMessages(ComUserMessageInputDto inputDto){
        BaseOutPutDto outPutDto = new BaseOutPutDto();
        try {
            ComUserMessageInputDto messageInputDto = inputDto;
            ComMiddleUserMessage userMessage = new ComMiddleUserMessage();
            BeanUtils.copyProperties(messageInputDto,userMessage);
            userMessage.setMessageId(UUID_MD5.getUUID());
            userMessage.setCreateTime(TimeUtil.getCurDateStamp());

            if(userMessage.getSourceUserId().equals(userMessage.getTargetUserId()) == false){

                if(comMiddleUserMessageMapper.insert(userMessage)>0){
                    {
//                        社区推送
                        UserInfoResData userInfoResData = userInfoService.findUserInfoResDataByUserId(userMessage.getSourceUserId());
                        JpushUtil.sendToAlias(userMessage.getTargetUserId(),userInfoResData.getNickName() + " " + userMessage.getPuchContent(), apnsProduction);
                    }
                    outPutDto.setStatus(Status.SUCCESS);
                }
            }

        }catch (Exception exc){
            outPutDto.setStatus(Status.ERROR);
            outPutDto.setMessage(exc.getMessage());
        }
        return outPutDto;
    }

    /**
     * 批量创建社区消息
     * @param inputDto
     * @return
     */

    public BaseOutPutDto createMessagesList(List<ComUserMessageInputDto> inputDto){
        BaseOutPutDto outPutDto = new BaseOutPutDto();
        try {
            List<ComMiddleUserMessage> comUserMessages = new ArrayList<>();
            for (ComUserMessageInputDto messageInputDto: inputDto
                 ) {
                ComMiddleUserMessage userMessage = new ComMiddleUserMessage();
                BeanUtils.copyProperties(messageInputDto,userMessage);
                userMessage.setMessageId(UUID_MD5.getUUID());
                userMessage.setCreateTime(TimeUtil.getCurDateStamp());
                userMessage.setIsRead(0);
                comUserMessages.add(userMessage);
            }

            comMiddleUserMessageMapper.insertList(comUserMessages);

            {
                //社区推送
                ComMiddleUserMessage first = comUserMessages.get(0);

                UserInfoResData userInfoResData = userInfoService.findUserInfoResDataByUserId(first.getSourceUserId());

                List<String> targetUserId = comUserMessages.parallelStream().map(ComMiddleUserMessage::getTargetUserId).collect(Collectors.toList());

                JpushUtil.sendToAliass(targetUserId,userInfoResData.getNickName() + " " + first.getPuchContent());

            }

            outPutDto.setStatus(Status.SUCCESS);

        }catch (Exception exc){
            outPutDto.setStatus(Status.ERROR);
            outPutDto.setMessage(exc.getMessage());
        }
        return outPutDto;
    }


    /**
     * 社区消息通用列表查询接口
     * @param inputDto
     * @param maijiToken
     * @return
     */
    public BaseOutPutDto<List<ComUserMessageOutputDto>> comCommonMessages(@RequestBody BaseInputDto<ComUserMessageQueryInputDto> inputDto, @RequestHeader("maijiToken")String maijiToken){
        BaseOutPutDto<List<ComUserMessageOutputDto>> outPutDto = new BaseOutPutDto();
        try {
            AppUser appUser = RedisUtil.getAppUserByRedis(redisTemplate, MyRedisConfig.REDISDATABASENO, maijiToken, userInfoService);
            if(appUser != null){
                String userId = appUser.getUuId();
                ComUserMessageQueryInputDto queryInputDto = inputDto.getData();
                if(queryInputDto.getTypes() != null){
                    outPutDto.setData(reloadUserMessages(userId,queryInputDto.getTypes(),inputDto.getMetaData().getPage(),inputDto.getMetaData().getSize()));
                }
                outPutDto.setStatus(Status.SUCCESS);
            }else{
                outPutDto.setStatus(Status.TOKENINVALID);
            }

            return outPutDto;
        }catch (Exception exc){
            outPutDto.setStatus(Status.ERROR);
            outPutDto.setMessage(exc.getMessage());
            return outPutDto;
        }

    }

    /**
     * 评论消息
     * @param inputDto
     * @param maijiToken
     * @return
     */
    public BaseOutPutDto<List<ComUserMessageOutputDto>> commentMessages(@RequestBody BaseInputDto inputDto, @RequestHeader("maijiToken")String maijiToken){
        BaseOutPutDto<List<ComUserMessageOutputDto>> outPutDto = new BaseOutPutDto();

        try {
            AppUser appUser = RedisUtil.getAppUserByRedis(redisTemplate, MyRedisConfig.REDISDATABASENO, maijiToken, userInfoService);
            if(appUser != null){
                String userId = appUser.getUuId();

                outPutDto.setData(reloadUserMessages(userId,Arrays.asList(ComUserMessageTypeEnum.Comment.getValue(),ComUserMessageTypeEnum.CommentComment.getValue(),ComUserMessageTypeEnum.Reply.getValue()),inputDto.getMetaData().getPage(),inputDto.getMetaData().getSize()));

                outPutDto.setStatus(Status.SUCCESS);
            }else{
                outPutDto.setStatus(Status.TOKENINVALID);
            }

            return outPutDto;
        }catch (Exception exc){
            outPutDto.setStatus(Status.ERROR);
            outPutDto.setMessage(exc.getMessage());
            return outPutDto;
        }

    }


    /**
     * 回复消息
     * @param inputDto
     * @param maijiToken
     * @return
     */
    public BaseOutPutDto<List<ComUserMessageOutputDto>> replyMessages(@RequestBody BaseInputDto inputDto, @RequestHeader("maijiToken")String maijiToken){
        BaseOutPutDto<List<ComUserMessageOutputDto>> outPutDto = new BaseOutPutDto();

        try {
            AppUser appUser = RedisUtil.getAppUserByRedis(redisTemplate, MyRedisConfig.REDISDATABASENO, maijiToken, userInfoService);
            if(appUser != null){
                String userId = appUser.getUuId();

                outPutDto.setData(reloadUserMessages(userId,Arrays.asList(ComUserMessageTypeEnum.Reply.getValue()),inputDto.getMetaData().getPage(),inputDto.getMetaData().getSize()));

                outPutDto.setStatus(Status.SUCCESS);
            }else{
                outPutDto.setStatus(Status.TOKENINVALID);
            }

            return outPutDto;
        }catch (Exception exc){
            outPutDto.setStatus(Status.ERROR);
            outPutDto.setMessage(exc.getMessage());
            return outPutDto;
        }

    }

    /**
     * 点赞消息
     * @param inputDto
     * @param maijiToken
     * @return
     */

    public BaseOutPutDto<List<ComUserMessageOutputDto>> praiseMessages(@RequestBody BaseInputDto inputDto, @RequestHeader("maijiToken")String maijiToken){
        BaseOutPutDto<List<ComUserMessageOutputDto>> outPutDto = new BaseOutPutDto();

        try {
            AppUser appUser = RedisUtil.getAppUserByRedis(redisTemplate, MyRedisConfig.REDISDATABASENO, maijiToken, userInfoService);
            if(appUser != null){
                String userId = appUser.getUuId();

                outPutDto.setData(reloadUserMessages(userId,Arrays.asList(ComUserMessageTypeEnum.Praise.getValue()),inputDto.getMetaData().getPage(),inputDto.getMetaData().getSize()));

                outPutDto.setStatus(Status.SUCCESS);
            }else{
                outPutDto.setStatus(Status.TOKENINVALID);
            }

            return outPutDto;
        }catch (Exception exc){
            outPutDto.setStatus(Status.ERROR);
            outPutDto.setMessage(exc.getMessage());
            return outPutDto;
        }
    }

    /**
     * 被关注消息
     * @param inputDto
     * @param maijiToken
     * @return
     */
    public BaseOutPutDto<List<ComUserMessageOutputDto>> followMessages(@RequestBody BaseInputDto inputDto, @RequestHeader("maijiToken")String maijiToken){
        BaseOutPutDto<List<ComUserMessageOutputDto>> outPutDto = new BaseOutPutDto();

        try {
            AppUser appUser = RedisUtil.getAppUserByRedis(redisTemplate, MyRedisConfig.REDISDATABASENO, maijiToken, userInfoService);
            if(appUser != null){
                String userId = appUser.getUuId();

                outPutDto.setData(reloadUserMessages(userId,Arrays.asList(ComUserMessageTypeEnum.Follow.getValue()),inputDto.getMetaData().getPage(),inputDto.getMetaData().getSize()));

                outPutDto.setStatus(Status.SUCCESS);
            }else{
                outPutDto.setStatus(Status.TOKENINVALID);
            }

            return outPutDto;
        }catch (Exception exc){
            outPutDto.setStatus(Status.ERROR);
            outPutDto.setMessage(exc.getMessage());
            return outPutDto;
        }
    }


    /**
     * 被@消息
     * @param inputDto
     * @param maijiToken
     * @return
     */
    public BaseOutPutDto<List<ComUserMessageOutputDto>> atMessages(@RequestBody BaseInputDto inputDto, @RequestHeader("maijiToken")String maijiToken){
        BaseOutPutDto<List<ComUserMessageOutputDto>> outPutDto = new BaseOutPutDto();

        try {
            AppUser appUser = RedisUtil.getAppUserByRedis(redisTemplate, MyRedisConfig.REDISDATABASENO, maijiToken, userInfoService);
            if(appUser != null){
                String userId = appUser.getUuId();

                outPutDto.setData(reloadUserMessages(userId,Arrays.asList(ComUserMessageTypeEnum.At.getValue()),inputDto.getMetaData().getPage(),inputDto.getMetaData().getSize()));

                outPutDto.setStatus(Status.SUCCESS);
            }else{
                outPutDto.setStatus(Status.TOKENINVALID);
            }

            return outPutDto;
        }catch (Exception exc){
            outPutDto.setStatus(Status.ERROR);
            outPutDto.setMessage(exc.getMessage());
            return outPutDto;
        }
    }



    /**
     * 消息列表
     * @param userId
     * @param value
     * @return
     */

    private List<ComUserMessageOutputDto> reloadUserMessages(String userId, Collection<?> value,Integer pageNo,Integer size){

        List<ComUserMessageOutputDto> userMessageOutputDtos = new ArrayList();

        EntityWrapper<ComMiddleUserMessage> entityWrapper = new EntityWrapper<>();
        ComMiddleUserMessage middleUserMessage = new ComMiddleUserMessage();
        middleUserMessage.setTargetUserId(userId);
        entityWrapper.setEntity(middleUserMessage);
        entityWrapper.in("type", value);
        entityWrapper.orderBy("create_time",false);
        Page<ComMiddleUserMessage> page = new Page(pageNo,size);
        List<ComMiddleUserMessage> userMessages = comMiddleUserMessageMapper.selectPage(page,entityWrapper);

        List<String> sourceUserId = userMessages.parallelStream().map(ComMiddleUserMessage::getSourceUserId).collect(Collectors.toList());
        if(sourceUserId != null && sourceUserId.size()>0){

            HashMap<String, Object> map2 = Maps.newHashMap();
            map2.put("userIds", sourceUserId);
            List<UserInfo> sourceUserList = userInfoService.selectList(map2);
            userMessageOutputDtos =
                    BaseService.dealWithOneToOne(userMessages, "getSourceUserId",
                            ComUserMessageOutputDto.class, "setSourceUser", sourceUserList, "getUserId", UserInfoResData.class);
        }

        if(userMessages != null && userMessages.size()>0){

//            List<ComMiddleUserMessage> newUserMessages = userMessages.stream().map(userMessage->
//                    userMessage.setIsRead(1)
//                    ).collect(Collectors.toList());
            comMiddleUserMessageMapper.update(new ComMiddleUserMessage().setIsRead(1) , entityWrapper);

            List<String> msgIds = userMessages.parallelStream().map(ComMiddleUserMessage::getMsgId).collect(Collectors.toList());
            if(msgIds != null && msgIds.size()>0){
                //获取动态主表内容
//                List<ComMsgBaseOutputDto> comMsgInfos = comMsgInfoMapper.selectBatchIds(msgIds).stream().map(msgInfo -> {
//                    ComMsgBaseOutputDto msgBaseOutputDto = new ComMsgBaseOutputDto();
//                    BeanUtils.copyProperties(msgInfo,msgBaseOutputDto);
//                    return msgBaseOutputDto;
//                }).collect(Collectors.toList());
//                //获取动态图片
//                HashMap<String, Object> map = Maps.newHashMap();
//                map.put("belongIds", msgIds);
//                List<UploadImageResData> msgImgs = uploadRecordService.findAllByBelongIds(map)
//                        .stream().map(uploadRecord -> {
//                            UploadImageResData uploadImageResData = new UploadImageResData();
//                            BeanUtils.copyProperties(uploadRecord, uploadImageResData);
//                            return uploadImageResData;
//                        }).collect(Collectors.toList());
//                List<ComRecsOutputDto> comMsgDtos = BaseService.dealWithOneToMany(comMsgInfos,"getMsgId",ComMsgBaseOutputDto.class,"setFiles",msgImgs,"getBelongId",UploadImageResData.class).stream().map(comMsgBaseOutputDto -> {
//                    ComRecsOutputDto recsOutputDto = new ComRecsOutputDto();
//                    recsOutputDto.setMsg(comMsgBaseOutputDto);
//                    recsOutputDto.setMsgId(comMsgBaseOutputDto.getMsgId());
//                    recsOutputDto.setUserId(comMsgBaseOutputDto.getUserId());
//                    return recsOutputDto;
//                }).collect(Collectors.toList());
//
//                //获取动态发送人
//                List<String> msgUserIds = comMsgInfos.parallelStream().map(ComMsgBaseOutputDto::getUserId).collect(Collectors.toList());
//                HashMap<String, Object> msgUsermap = Maps.newHashMap();
//                map.put("userIds", msgUserIds);
//                List<UserInfo> userOfMsgList = userInfoService.selectList(msgUsermap);
//
//                comMsgDtos = BaseService.dealWithOneToOne(comMsgDtos,"getUserId",ComRecsOutputDto.class,"setUser",userOfMsgList,"getUserId",UserInfoResData.class);


                List<ComRecsOutputDto> comMsgDtos = new ArrayList();
                List<ComMsgInfo> comMsgInfos = new ArrayList();
                comMsgInfos = comMsgInfoMapper.findListByMsgIds(msgIds,userId);

                userMessageOutputDtos = BaseService.dealWithOneToOne(userMessageOutputDtos,"getMsgId",ComUserMessageOutputDto.class,"setMsg",communityService.reloadMsgInfosNoDelete(comMsgInfos,userId).getData(),"getMsgId", ComRecsOutputDto.class);
            }



            List<String> curCommentIds = userMessages.parallelStream().map(ComMiddleUserMessage::getCurCommentId).collect(Collectors.toList());
            if(curCommentIds != null && curCommentIds.size()>0){
//                List<ComCommentOutputDto> curComments = comCommentMapper.selectBatchIds(curCommentIds).stream().map(comment ->{
//                    ComCommentOutputDto commentOutputDto = new ComCommentOutputDto();
//                    BeanUtils.copyProperties(comment,commentOutputDto);
//                    return commentOutputDto;
//                }).collect(Collectors.toList());
//
//                List<String> curComSourceUserId = curComments.parallelStream().map(ComCommentOutputDto::getSourceUserId).collect(Collectors.toList());
//                HashMap<String, Object> curComSourceMap2 = Maps.newHashMap();
//                curComSourceMap2.put("userIds", curComSourceUserId);
//                List<UserInfo> curComSourceUserList = userInfoService.selectList(curComSourceMap2);
//                curComments = BaseService.dealWithOneToOne(curComments,"getSourceUserId",ComCommentOutputDto.class,"setSourceUser",curComSourceUserList,"getUserId",UserInfoResData.class);
//
//
//                List<String> curComTargetUserId = curComments.parallelStream().map(ComCommentOutputDto::getSourceUserId).collect(Collectors.toList());
//                HashMap<String, Object> curComTargetMap2 = Maps.newHashMap();
//                curComSourceMap2.put("userIds", curComTargetUserId);
//                List<UserInfo> curComTargetUserList = userInfoService.selectList(curComTargetMap2);
//                curComments = BaseService.dealWithOneToOne(curComments,"getTargetUserId",ComCommentOutputDto.class,"setTargetUser",curComTargetUserList,"getUserId",UserInfoResData.class);


                List<ComCommentOutputDto> curComments = comCommentMapper.findListByCommentids(curCommentIds,userId).stream().map(comment ->{
                    ComCommentOutputDto commentOutputDto = new ComCommentOutputDto();
                    BeanUtils.copyProperties(comment,commentOutputDto);
                    UserInfoResData sourceUserInfo = new UserInfoResData();
                    BeanUtils.copyProperties(comment.getSourceUser(),sourceUserInfo);
                    commentOutputDto.setSourceUser(sourceUserInfo);
                    UserInfoResData targetUserInfo = new UserInfoResData();
                    BeanUtils.copyProperties(comment.getTargetUser(),targetUserInfo);
                    commentOutputDto.setTargetUser(targetUserInfo);
                    return commentOutputDto;
                }).collect(Collectors.toList());


                userMessageOutputDtos = BaseService.dealWithOneToOne(userMessageOutputDtos,"getCurCommentId",ComUserMessageOutputDto.class,"setCurComment",curComments,"getCommentId", ComCommentOutputDto.class);
            }

            List<String> lastCommentIds = userMessages.parallelStream().map(ComMiddleUserMessage::getLastCommentId).collect(Collectors.toList());
            if(lastCommentIds != null && lastCommentIds.size()>0){
//                List<ComCommentOutputDto> lastComments = comCommentMapper.selectBatchIds(lastCommentIds).stream().map(comment ->{
//                    ComCommentOutputDto commentOutputDto = new ComCommentOutputDto();
//                    BeanUtils.copyProperties(comment,commentOutputDto);
//                    return commentOutputDto;
//                }).collect(Collectors.toList());

//                List<String> curComSourceUserId = lastComments.parallelStream().map(ComCommentOutputDto::getSourceUserId).collect(Collectors.toList());
//                HashMap<String, Object> curComSourceMap2 = Maps.newHashMap();
//                curComSourceMap2.put("userIds", curComSourceUserId);
//                List<UserInfo> curComSourceUserList = userInfoService.selectList(curComSourceMap2);
//                lastComments = BaseService.dealWithOneToOne(lastComments,"getSourceUserId",ComCommentOutputDto.class,"setSourceUser",curComSourceUserList,"getUserId",UserInfoResData.class);
//
//
//                List<String> curComTargetUserId = lastComments.parallelStream().map(ComCommentOutputDto::getSourceUserId).collect(Collectors.toList());
//                HashMap<String, Object> curComTargetMap2 = Maps.newHashMap();
//                curComSourceMap2.put("userIds", curComTargetUserId);
//                List<UserInfo> curComTargetUserList = userInfoService.selectList(curComTargetMap2);
//                lastComments = BaseService.dealWithOneToOne(lastComments,"getTargetUserId",ComCommentOutputDto.class,"setTargetUser",curComTargetUserList,"getUserId",UserInfoResData.class);

                List<ComCommentOutputDto> lastComments = comCommentMapper.findListByCommentids(lastCommentIds,userId).stream().map(comment ->{
                    ComCommentOutputDto commentOutputDto = new ComCommentOutputDto();
                    BeanUtils.copyProperties(comment,commentOutputDto);
                    UserInfoResData sourceUserInfo = new UserInfoResData();
                    BeanUtils.copyProperties(comment.getSourceUser(),sourceUserInfo);
                    commentOutputDto.setSourceUser(sourceUserInfo);
                    UserInfoResData targetUserInfo = new UserInfoResData();
                    BeanUtils.copyProperties(comment.getTargetUser(),targetUserInfo);
                    commentOutputDto.setTargetUser(targetUserInfo);
                    return commentOutputDto;
                }).collect(Collectors.toList());


                userMessageOutputDtos = BaseService.dealWithOneToOne(userMessageOutputDtos,"getLastCommentId",ComUserMessageOutputDto.class,"setLastComment",lastComments,"getCommentId", ComCommentOutputDto.class);
            }
        }
        return userMessageOutputDtos;

    }

}
